package m1;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.util.Scanner;

public class Producer {

    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
        DefaultMQProducer p = new DefaultMQProducer("producerGroup1");
        p.setNamesrvAddr("192.168.64.141:9876");

        p.start();
        while (true) {
            System.out.println("输入消息：");
            String s = new Scanner(System.in).nextLine();
            Message message = new Message("Topic1", "Tag1", s.getBytes());
            // 设置延迟
            message.setDelayTimeLevel(3);

            SendResult send = p.send(message);
            System.out.println(send);
        }
    }

}
